-module(externalprogram_supervisor).
-behavior(supervisor).

% API
-export([start_link/3]).

% supervisor callbacks
-export([init/1]).

start_link(Type,NumWorkers,ExtProg) ->
  supervisor:start_link({local,
                          list_to_atom(atom_to_list(Type) ++ "_supervisor")},
                        ?MODULE,
                        {Type,NumWorkers,ExtProg}).

init({Type, NumWorkers,ExtProg}) ->
  {ok,
   {{one_for_one,
     3,
     10},
    [begin
         Id=list_to_atom(atom_to_list(Type) ++ integer_to_list(Which)),
         {Id,
          {external_program,
           start_link,
           [Type,Id,ExtProg]},
          permanent,
          _Timeout=10*1000,
          worker,
          [external_program]}
       end
     || Which <- lists:seq(1,NumWorkers)]}}.
